package com.ruoyi.flowable.listener;

import org.flowable.engine.ProcessEngine;
import org.flowable.engine.ProcessEngines;
import org.flowable.engine.TaskService;
import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.api.Task;
import org.flowable.task.service.delegate.DelegateTask;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * 用户任务监听器
 *
 * @author KonBAI
 * @since 2023/5/13
 */
@Component(value = "userTaskListener")
public class UserTaskListener implements TaskListener {

    /**
     * 注入字段（名称与流程设计时字段名称一致）
     */
    // private FixedValue field;

    @Override
    public void notify(DelegateTask delegateTask) {
        //TODO 实现你的任务监听器逻辑
        System.out.println("执行任务监听器...");
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        TaskService taskService = processEngine.getTaskService();
        Map<String, Object> variables = taskService.getVariables(delegateTask.getId());// 可获取节点表单

        Task task = taskService.createTaskQuery().taskId(delegateTask.getId()).singleResult();
        List<Task> taskList = taskService.createTaskQuery().processInstanceId(delegateTask.getProcessInstanceId()).list();//只能取到当前节点,要修改下个节点的候选人,需在下个节点开始前

        String formKey = delegateTask.getFormKey();
        String assignee = delegateTask.getAssignee();
        String category = delegateTask.getCategory();
        String processDefinitionId = delegateTask.getProcessDefinitionId();
        String processInstanceId = delegateTask.getProcessInstanceId();

    }

}
